<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增创业津贴奖励配置')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-allowanceAward-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">活动名称：</label>
            <div class="col-sm-8">
                <input name="actName" maxlength="50" required class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">展业端管理编号：</label>
            <div class="col-sm-8">
                <input name="agentNum" onclick="selectAllAgent()" readonly id="teamAgentNum" type="text" class="form-control" required>
                <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">展业端管理名称：</label>
            <div class="col-sm-8">
                <input name="agentName" class="form-control" id="teamAgentName" type="text" required readonly >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型：</label>
            <div class="col-sm-8">
                <select name="type" onchange="teamValue(this)" class="form-control m-b" required>
                    <option value="">请选择</option>
                    <option value="1">团长</option>
                    <option value="2">资深总监</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">活动状态：</label>
            <div class="col-sm-8">
                <select name="status" class="form-control m-b" required>
                    <option value="">请选择</option>
                    <option value="1">启用</option>
                    <option value="0">禁用</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">团类型：</label>
            <div class="col-sm-8">
                <select name="teamType" class="form-control m-b">
                    <option value="">所有</option>
                    <option value="1">老团</option>
                    <option value="2">新团</option>
                </select>
            </div>
        </div>
        <div id="teamValue" style="display: none">
            <div class="form-group">
                <label class="col-sm-3 control-label">团奖励类型：</label>
                <div class="col-sm-8">
                    <select name="teamAwardType" class="form-control m-b">
                        <option value="4">电签</option>
                        <option value="0">传统</option>
                        <option value="5">GB传统</option>
                        <option value="7">GB电签二</option>

                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">团长编号：</label>
                <div class="col-sm-8">
                    <input name="teamNum" readonly id="teamNum" onclick="getTeamInfo()" type="text" class="form-control">
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">团长名称：</label>
                <div class="col-sm-8">
                    <input name="teamName" class="form-control" id="teamName" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">团长奖励比例：</label>
                <div class="col-sm-8">
                    <input name="teamAward" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">累计交易量金额：</label>
            <div class="col-sm-8">
                <input name="totalMoney" maxlength="10" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">奖励比例：</label>
            <div class="col-sm-8">
                <input name="award" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">活动开始时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="actStartDate" required class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">活动结束时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="actEndDate" required class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: utils-js" />
<script th:inline="javascript">
    var prefix = ctx + "team/allowanceAward"
    var teamInfo = ctx + "team/teamYlInfo"
    $("#form-allowanceAward-add").validate({
        focusCleanup: true
    });

    $("input[name='actStartDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    $("input[name='actEndDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    /**
     * 选择展业端管理
     */
    function selectAllAgent() {
        var url =teamInfo+ "/selectAllAgent";
        $.modal.open("选择展业端管理信息" , url, '1100',"500");
        $("#teamNum").val("")
        $("#teamName").val("")
    }

    function submitHandler() {
        if ($.validate.form()) {
            if (!$.vali.money($("input[name='totalMoney']").val())){
                $.modal.alertError("请输入正确的累计交易量金额");
                return;
            }
            $.operate.save(prefix + "/add", $('#form-allowanceAward-add').serialize());
        }
    }

    /**
     * 根据展业端管理编号，获取团长信息
     */
    function getTeamInfo(){
        var agentNum = $("#teamAgentNum").val();
        if(agentNum != ''){
            $.ajax({
                type: "post",
                data: agentNum,
                dataType: "html",
                url: teamInfo+ "/getTeamInfo",
                success: function (data) {
                    var obj = JSON.parse(data)
                    if(obj.data == null){
                        $.modal.alertError("当前展业端管理无直属团长信息");
                    }
                    $("#teamNum").val(obj.data.PARENT_YL_ID)
                    $("#teamName").val(obj.data.PARENT_YL_NAME)
                }
            })
        }
    }

    /**
     * 显示隐藏团长信息
     */
    function teamValue(value){
        if(value.value == '2'){
            $("#teamValue").removeAttrs("style")
        }else{
            $("#teamValue").attr("style","display:none")
        }
    }
</script>
</body>
</html>
